﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using AOP.Filter.Result;
using Microsoft.AspNetCore.Mvc;
using MODEL.Model;
using SERVICE.Admin.IService;

namespace Admin.Controllers.System
{
    [Description("系统设置")]
    public class AddRuleController : Controller
    {
        ISyetemService syetemService;
        public AddRuleController(ISyetemService syetemService)
        {
            this.syetemService = syetemService;
        }
        [Description("添加角色"), Native]
        public IActionResult Index(int id = 0)
        {
            ViewData["id"] = id;
            return View();
        }
        /// <summary>
        /// 添加权限
        /// </summary>
        /// <param name="name"></param>
        /// <param name="paths"></param>
        /// <returns></returns>
        [Description("添加角色"), HttpPost]
        public bool Add(string name, IList<string> actionNames)
        {
            return syetemService.AddRule(name, actionNames);
        }
        /// <summary>
        /// 查看角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Description("查看角色"), HttpGet]
        public object GetRule(int id)
        {
            var rule = syetemService.GetRule(id);
            return new { rule.name, paths = rule.SystemJurisdictions.Select(x => x.name).ToList() };
        }
        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="paths"></param>
        /// <returns></returns>
        [Description("修改角色"), HttpPost]
        public bool Mdy(int id, string name, IList<string> actionNames)
        {
            return syetemService.MdyRule(id, name, actionNames);
        }
    }
}